﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using org.smslib.modem;
using org.smslib.modem.athandler;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace SmsUI.SmsCore
{
    public class WavecomModemGatewayCall : IPModemGateway
    {
        //public override bool sendMessage(org.smslib.OutboundMessage msg)
        //{
        //    if (getStatus() != GatewayStatuses.STARTED) return false;
        //    getATHandler().sendCustomATCommand(string 

        //    return true;
        //}
        public WavecomModemGatewayCall(string id, string ipName, int ipPort, string manufacturer, string model) :
            base(id, ipName, ipPort, manufacturer, model)
        {

            AATHandler at = new ATHandler_Wavecom_AddCall(this);

            base.setAtHandler(at);

        }
        //public override string sendCustomATCommand(string atCommand)
        //{
        //    return getATHandler().sendCustomATCommand(atCommand);
        //    // return base.sendCustomATCommand(atCommand);
        //}
        public override bool sendMessage(org.smslib.OutboundMessage msg)
        {
            if (msg.getText() == SmsHelper.SmsHelper.IsCallNum)
            {

                bool re = false;
                lock (getModemDriver().getSYNCCommander())
                {
                    string re2 = sendCustomATCommand(msg.getRecipient());
                    re=bool.Parse(re2);
                    if (re)
                    {

                        msg.setMessageStatus(org.smslib.OutboundMessage.MessageStatuses.SENT);
                        msg.setFailureCause(org.smslib.OutboundMessage.FailureCauses.NO_ERROR);
                    }
                }
                return re;
            }
            bool sendResult = false;
            try
            {
                lock (getModemDriver().getSYNCCommander())
                {
                    sendResult = base.sendMessage(msg);
                }
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }

            return sendResult;
        }
    }
}
